<template>
    <div>
        <div v-for="(item,index,key) in convert(data)"
            :key="key"
            class="content">
            <p v-if="!isImg(item)"
                class="fontColorBlackTitle answerConDetail">{{ item }}</p>
            <img v-if="isImg(item)"
                :src="item" />
        </div>
    </div>
</template>

<script>
export default {
    props:["data"],
    data () {
        return {

        }
    },
    methods:{
        //判断是否为图片
        isImg(val) {
            if (val.indexOf(".jpg") == -1 && val.indexOf(".png") == -1 && val.indexOf(".jpeg") == -1 && val.indexOf(".gif") == -1)
            {
                return false;
            }
            else
            {
                return true;
            }
        },
        //处理那个蛋疼的数据
        convert:function(res){
            let resContent = res;
            let FSplitCon = resContent.split("###<");
            let conIntercept = [];
            let imgObj;
            for (let i in FSplitCon) {
                let SSplitCon = FSplitCon[i].split(">###");
                conIntercept.push(...SSplitCon);
            }
            for (let x in conIntercept) {
                if (conIntercept[x].indexOf("src") != -1) {
                // conIntercept[x].substr(1).substring(-1,0)
                if (conIntercept[x][1] == "{") {
                    let cutFront = conIntercept[x].substr(1);
                    let cutLast = cutFront.substring(0, cutFront.length - 1);
                    imgObj = JSON.parse(cutLast);
                }
                else {
                    imgObj = JSON.parse(conIntercept[x]);
                }
                let imgSrc = "";
                for (var key in imgObj) {
                    if (key == "src") {
                        imgSrc = imgObj[key];
                    }
                }
                conIntercept.splice(x, 1, imgSrc);
                }
            }
            return conIntercept;
        },
    },
    mounted(){

    }
}
</script>

<style lang="scss" scoped>
    img{
        display: none;
        max-width: 100%;
    }
</style>
